package com.cn.customer.housekeeping.housekeepingb.ui.adapter;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cn.customer.housekeeping.housekeepingb.R;
import com.cn.customer.housekeeping.housekeepingb.bean.ProdctBean;

import java.util.List;


/**
 * GridView加载数据的适配器
 *
 * @author Administrator
 */
public class MyGridViewchoiceTimeAdpter extends BaseAdapter {

    private Context context;
    public List<ProdctBean> lists;//数据源

    ColorStateList colorFa5c5b,colorBlack;
    public MyGridViewchoiceTimeAdpter(Context context, List<ProdctBean> lists
                               ) {
        Resources resource = (Resources)context.getResources();
         colorFa5c5b= (ColorStateList) resource.getColorStateList(R.color.colormain_fa5c5b);
         colorBlack = (ColorStateList) resource.getColorStateList(R.color.black);
        this.context = context;
        this.lists = lists;
        for (int i=0; i<lists.size(); i++) {
            lists.get(i).setSelect(true);
        }

    }


    public void changeStatus(int select) {
        for (int i=0; i<lists.size(); i++) {
            lists.get(i).setSelect(false);
        }
        lists.get(select).setSelect(true);
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return lists.size() ;
    }

    @Override
    public ProdctBean getItem(int arg0) {
        // TODO Auto-generated method stub
        return lists.get(arg0 );
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_head_choicetimegridview, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.item_name);
            holder.view5 = (ImageView) convertView.findViewById(R.id.view5);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        if (lists.get(position).isSelect()) {
            holder.view5.setVisibility(View.VISIBLE);
            holder.tv_name.setTextColor(colorFa5c5b);
        }else {
            holder.view5.setVisibility(View.INVISIBLE);
            holder.tv_name.setTextColor(colorBlack);
        }
        holder.tv_name.setText(lists.get(position).getName() + "");



        return convertView;
    }

    static class ViewHolder {
        private TextView tv_name;
        private ImageView view5;
    }
}